package com.controller;


import com.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.Resource;

/**
 * 统一页面跳转管理
 *
 */
@Controller
@RequestMapping
public class PageController {

    @Resource
    private UserService userService;

    @PostMapping("/userRegister")
    public String userRegister(@RequestParam("username") String username,
                               @RequestParam("password") String password ,
                               @RequestParam("phoneNumber") String phoneNumber){
        if (username != null && password != null && phoneNumber != null)
        {
            if (userService.register(username,password,phoneNumber))
            {
                return "login";
            }
        }
        return "registerError";
    }

    @PostMapping("/doModifyPwd")
    public String modifyPassword(@RequestParam("username") String username,
                                 @RequestParam("password") String password) {
        if(userService.modifyPwd(username,password)){
            return "register";
        }else {
            return "registerError";
        }
    }

    @RequestMapping("/modifyPwd")
    public String modifyPwd(){
        return "modifyPwd";
    }

    @RequestMapping("/register")
    public String register(){
        return "register";
    }

    @RequestMapping("/registerError")
    public String registerError(){
        return "registerError";
    }

    @RequestMapping("/index")
    public String index(){ return "index"; }

    @RequestMapping("/login")
    public String login(){ return "login"; }

    @RequestMapping("/addressBook")
    public String addressBook(){
        return "addressBook";
    }

    @RequestMapping ("/contactDetails")
    public String contactDetails(){
        return "contactDetails";
    }

    @RequestMapping("/newContact")
    public String newContact(){ return "newContact"; }

    @RequestMapping("/changeContactDetails")
    public String changeContactDetails() { return "changeContactDetails";}

    @RequestMapping("/addNewError")
    public String addNewError() { return "addNewError";}

    @RequestMapping("/updateError")
    public String updateError() { return "updateError";}

    @RequestMapping("/outerContactDetails")
    public String outerContactDetails() { return "outerContactDetails"; }

    @RequestMapping("/addToMyContacts")
    public String addToMyContacts() { return "addToMyContacts"; }

    @RequestMapping("/recycleBin")
    public String recycleBin() { return "recycleBin"; }

    @RequestMapping("/403error")
    public String error(){return "403error" ;}
}
